<?php							
		class CDetail extends database
		{
			var $table = 'cdb_detail';
			
			
			
			//$col co the la string hay so deu duoc
			//1: about
			//2:term
			//3: contact
			public function CDetailGetColumn($col)
			{
				$arr = $this->CDetailList ();
				
				$numOfRecord = count ($arr);
				if(is_array($arr))
				{
					$numOfRecord = count ($arr);
					return $arr[$numOfRecord-1][$col];
				}
				else
					return -1;	
			}
			

			//$col co the la string hay so deu duoc
			//1: about
			//2:term
			//3: contact
			public function CDetailUpdateColumn($id = 1,$col,$content,$status)
			{
				$sql ="";
				switch($col)
				{
					case 1:
						$sql = "update $this->table set about ='{$content}',status_about='{$status}' where id = '{$id}' ";
					break;
					case 2:
						$sql = "update $this->table set term ='{$content}',status_term='{$status}' where id = '{$id}' ";
					break;
					case 3:
						$sql = "update $this->table set contact ='{$content}',status_contact='{$status}' where id = '{$id}' ";
					break;
				}
				
		
				$this->setQuery($sql);
				$this->query();
				return mysql_affected_rows();
			}		
			
			
			
			public function CDetailList ()
			{
				$sql ="select * from {$this->table} "	;
				$this->setQuery($sql);
				$this->query();
				$arr = $this->loadAllRow();
				
				$numOfRow = mysql_affected_rows();
				
				if($numOfRow>0)
					return $arr;
				else
					return -1;	
			}
			
			public function CDetailDetail ($id)
			{
				$sql="select * from $this->table where id='{$id}'";
				$this->setQuery($sql);
				$this->query();
				$arr=$this->loadAllRow();
				
				$numOfRow = mysql_affected_rows();
				if($numOfRow>0)
					return $arr[0];
				else
					return -1;
			}
			
			
			
			public function CDetailAdd ($id,$content,$status)
			{
				$sql = "INSERT INTO {$this->table} (`id`,`content`,`status`)
	VALUES ('{$id}','{$content}','{$status}');";
				
				$this->setQuery($sql);
				$this->query();	
				return mysql_affected_rows();
				
			}
			
			public function CDetailUpdate ($id,$content,$status)
			{
				$sql = "update $this->table set content ='{$content}',status ='{$status}' where id = '{$id}' ";
			
				$this->setQuery($sql);
				$this->query();
				return mysql_affected_rows();
			}
			
			public function CDetailDelete($id)
			{
				$sql="Delete from  $this->table where id='{$id}'";
				$this->setQuery($sql);
				$this->query();
				return mysql_affected_rows();
			}
			
		}
	
	
	
	?>